<?php
session_start();
$cdnUrl='./';
include_once './c/config.php';
include 'jssdk.php';
$jssdk = new JSSDK($appId, $secret);
$signPackage = @$jssdk->GetSignPackage();
$pin=array(
    '海信电视'=>array('HZ65A8V','HZ55A8','HZ65S7E','HZ65U9E','88L5V'),
    '海信空调'=>array('50X800','72X800','50X630','72X630','35X800'),
    '科龙空调'=>array('35QW','26QW','50HY','72HY','50LY','72LY'),
    '海信冰箱'=>array('BCD-555WTDGVBPIV','BCD-602WTDGVBP'),
    '海信冷柜'=>array('JC-168PUT'),
    '容声冰箱'=>array('558WWKK1FPG','601WKS1HPG','516WKK1FPGA','550WKK1FPGA'),
    '容声冷柜'=>array('JC-226WPYL','JC-166PSY'),
    '海信洗衣机'=>array('XQG120-BH1406AYFI','XQG120-D1400YFTI','XQG120-D1400YFIG'),
    
);
$xiao=$dian='';
if (isset($_COOKIE["xiao"])){
    $xiao=$_COOKIE["xiao"];
}
if (isset($_COOKIE["dian"])){
    $dian=$_COOKIE["dian"];
}

//    '容声洗衣机'=>array('')
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>海信-卡券核销</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<style>
html,body{width:100%;font-size:12px;font-family:Helvetica,Tahoma, Arial, STXihei,Microsoft YaHei, Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;}
body{-webkit-overflow-scrolling: touch;overflow-scrolling: touch;overflow-y: scroll;}
body, div{padding:0px;margin:0px auto;max-width:750px;}
.weui-dialog{position:fixed;z-index:5000;width:80%;max-width:300px;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);background-color:#FFF;text-align:center;border-radius:3px;overflow:hidden}.weui-dialog__hd{padding:1.3em 1.6em .5em}.weui-dialog__title{font-weight:400;font-size:36px}.weui-dialog__bd{padding:0 1.6em .8em;min-height:40px;font-size:15px;line-height:1.3;word-wrap:break-word;word-break:break-all;color:#999}.weui-dialog__bd:first-child{padding:1.2em 20px .1em;color:#353535}.weui-dialog__ft{position:relative;line-height:48px;font-size:18px;display:-webkit-box;display:-webkit-flex;display:flex}.weui-dialog__ft:after{content:" ";position:absolute;left:0;top:0;right:0;height:1px;border-top:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(.5);transform:scaleY(.5)}.weui-dialog__btn{display:block;-webkit-box-flex:1;-webkit-flex:1;flex:1;color:#3CC51F;text-decoration:none;-webkit-tap-highlight-color:transparent;position:relative}.weui-dialog__btn:active{background-color:#EEE}.weui-dialog__btn:after{content:" ";position:absolute;left:0;top:0;width:1px;bottom:0;border-left:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleX(.5);transform:scaleX(.5)}.weui-dialog__btn:first-child:after{display:none}.weui-dialog__btn_default{color:#353535}.weui-dialog__btn_primary{color:#0BB20C}@media screen and (min-width:1024px){.weui-dialog{width:35%}}.weui-mask{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0;background:rgba(0,0,0,.6)}
.weui-mask_transparent{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0}
.js_dialog{display:none;}
-webkit-touch-callout:none;
-webkit-user-select:none;
html{-ms-touch-action:none;}
div,img{-webkit-tap-highlight-color:rgba(0,0,0,0);}
*{-webkit-text-size-adjust: none;}
.simg{position:absolute;display:block;}
a{text-decoration:none;}
.txt{position:absolute;text-indent:4px;color:#787c7f;font-size:12px;z-index:2;border:none;background:transparent;}
.txt::-webkit-input-placeholder{text-align:left;color:#a2a2a2;}
select{position:absolute;color:#787c7f;display:block;background:transparent;border:0px;text-indent:4px;font-size:12px;-webkit-appearance:none;}
.container{position:relative;width:100%;height:auto;overflow:hidden;}
.page{position:absolute;width:100%;height:100%;display:none;top:0;left:0;}
.p-b, .thebg{position:absolute;width:100%;top:0;left:0;}
.xi-qr{opacity:0;height:100%;}
.logo{position:absolute;top:0;left:0;z-index:3;}
.p-bg{position:absolute;width:100%;bottom:0;left:0;}
</style></head>
<body>
<div class="container">
    <div class="p1 page">
       <img class="p-bg" src="<?php echo $cdnUrl; ?>img/b.jpg" />
       <img class="logo" src="<?php echo $cdnUrl; ?>img/logo.png" />
	   <div class="thebg">
	      <img class="p-b" src="<?php echo $cdnUrl; ?>img/user.png" />
	      <select id="p1-pin" name="pin">
	      	<?php foreach ($pin as $k=>$v){ ?>
	      	<option value="<?php echo $k; ?>"><?php echo $k; ?></option>
	      	<?php } ?>
	      </select>
	      <select id="p1-xing" name="xing">
	      	<?php foreach ($pin['海信电视'] as $k=>$v){ ?>
	      	<option value="<?php echo $v; ?>"><?php echo $v; ?></option>
	      	<?php } ?>
	      </select>
	      <input id="p1-dian" class="txt" name="p1-dian" type="text" value="<?php echo $dian; ?>" placeholder="" />
	      <input id="p1-dui" class="txt" name="p1-dui" type="text" value="" placeholder="" />
	      <div class="p1-sao simg"></div>
	      <input id="p1-xiao" class="txt" name="p1-xiao" type="text" value="<?php echo $xiao; ?>" placeholder="" />
	      
	      
	      
	      <div class="p1-quer simg"></div>
	     
	   </div>
    </div>
    
    <div class="p2 page">
       <img class="p-bg" src="<?php echo $cdnUrl; ?>img/b.jpg" />
       <img class="logo" src="<?php echo $cdnUrl; ?>img/logo.png" />
	   <div class="thebg">
	     <img class="p-b" src="<?php echo $cdnUrl; ?>img/up2.png" />
	     <div class="p2-back simg"></div>
	   </div>
    
    </div>
    
    <div class="js_dialog">
       <div class="weui-mask"></div>
       <div class="weui-dialog">
                <div class="weui-dialog__bd weui-msg"></div>
                <div class="weui-dialog__ft">
                    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary weui-btn">知道了</a>
                </div>
        </div>
     </div>
    
</div>
<script src="http://mat1.gtimg.com/libs/jquery2/2.1.4/jquery2.min.js"></script>
<script src="<?php echo $cdnUrl ?>js/pxloader-images.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
_h=h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
var _rate=(sWidth/750);
if(h<_rate*1206){h=_rate*1206;}
var _img=['user.jpg'];
var loader = new PxLoader();
for(var i=0; i<_img.length; i++){loader.addImage('./img/'+_img[i]);}
loader.start();
var _mbg=document.getElementById("mbg");
loader.addCompletionListener(function(e){
	   $(".p1").fadeIn(800);
});
$(function(){
	$('.container').width(sWidth).height(h);
	$('.thebg, .p-b').width(sWidth).height(_rate*1206);
	$('.logo').width(_rate*233).height(_rate*81);
	$('#p1-pin').width(_rate*364).height(_rate*50).css({"top":_rate*588,"left":_rate*194});
	$('#p1-xing').width(_rate*364).height(_rate*50).css({"top":_rate*656,"left":_rate*194});
	$('#p1-dian').width(_rate*364).height(_rate*50).css({"top":_rate*724,"left":_rate*194});
	$('#p1-dui').width(_rate*364).height(_rate*50).css({"top":_rate*792,"left":_rate*194});
	$('.p1-sao').width(_rate*124).height(_rate*140).css({"top":_rate*752,"left":_rate*572});
 
	$('#p1-xiao').width(_rate*364).height(_rate*50).css({"top":_rate*862,"left":_rate*194});
	$('.p1-quer').width(_rate*364).height(_rate*70).css({"top":_rate*960,"left":_rate*194});

	$('.p2-back').width(_rate*440).height(_rate*300).css({"top":_rate*840,"left":_rate*160});
	
	
	
	wx.config({
        appId: '<?php echo $signPackage["appId"];?>',timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'showMenuItems', 'hideMenuItems','scanQRCode']
    });
	
	var _pin=<?php echo json_encode($pin); ?>;
	$("#p1-pin").change(function(){
		var _xing=_pin[$(this).val()];
		var _html='';
		console.log(_xing);
		$(_xing).each(function(id,key){
           //var _data=$(this).val();
           console.log(key);
           if('' == key){
        	   _html+='<option value="">不限</option>'; 
           }else{
        	   _html+='<option value="'+key+'">'+key+'</option>'; 
           }
		});
		$('#p1-xing').html(_html);
		
		
	});
	
	console.log(_pin);
	
	if(h > _rate*1206){
	   var _cha= (h - _rate*1206)/2;
	   if(_cha > 0){
	      $('.thebg').css({"top":_cha});
	      $('.logo').css({"top":_cha/3}); 
	   }   
	}


	$('.p1-quer').click(function(){
        var _pin=$("#p1-pin").val();
        var _xing=$("#p1-xing").val();
        var _dian=$("#p1-dian").val();
        var _dui=$("#p1-dui").val();
        var _xiao=$("#p1-xiao").val();
        if('' == _dian){
       		$(".weui-msg").html("请输入门店");
            $(".js_dialog").show();
            return;  
        }
        if('' == _dui){
       		$(".weui-msg").html("请输入兑换码");
            $(".js_dialog").show();
            return;  
        }
        if('' == _xiao){
       		$(".weui-msg").html("请输入核销码");
            $(".js_dialog").show();
            return;  
        }
        $.post("./api/?c=user", {pin:_pin,xing:_xing,
        	dian:_dian,dui:_dui,xiao:_xiao
            }, function(data){
              console.log(data);
              if('has' == data.msg){
            	  $(".weui-msg").html("兑换码已使用");
                  $(".js_dialog").show();
                  return; 
               }else if('buzai' == data.msg){
            	   $(".weui-msg").html("请输入正确的兑换码");
                   $(".js_dialog").show();
                   return; 
               }else if('nxma' == data.msg){
            	   $(".weui-msg").html("请输入正确的核销码");
                   $(".js_dialog").show();
                   return; 
               }else{
            	   $(".p1").fadeOut();
                   $(".p2").fadeIn();
               }
  			  
		}, "json"); 

        $.post("cook.php", {dian:_dian,xiao:_xiao}, function(data){}, "json"); 
	});

	
	
	$('.p1-sao').click(function(){
		wx.scanQRCode({
			  needResult: 1,  
			  scanType: ["qrCode","barCode"],  
			  success: function (res) {
			    var data = res.resultStr;
			    var _tmpData=data.split(",");
			    $("#p1-dui").val(_tmpData[1]);
			    
                  //alert(result);
			   }
			});
 
    }); 

	$('.p2-back').click(function(){
         $(".p2").fadeOut();
         $(".p1").fadeIn();
	 }); 	

	$(".js_dialog").click(function(){
        $(".js_dialog").hide();
	 }); 	
	 
});
</script></body></html>